/*
 * @Author: szx
 * @Date: 2022-03-21 12:41:13
 * @LastEditTime: 2022-03-21 12:52:56
 * @Description:
 * @FilePath: \leetcode\600-699\653\653.js
 */
function TreeNode(val, left, right) {
    this.val = val === undefined ? 0 : val;
    this.left = left === undefined ? null : left;
    this.right = right === undefined ? null : right;
}

/**
 * @param {TreeNode} root
 * @param {number} k
 * @return {boolean}
 */
var findTarget = function (root, k) {
    const set = new Set();
    const preorder = (root) => {
        if (!root) return false;
        const left = preorder(root.left);
        if (set.has(k - root.val)) return true;
        set.add(root.val);
        const right = preorder(root.right);
        return left || right;
    };
    return preorder(root);
};
